# -*- coding: utf-8 -*-

'''
    【简介】
	PySide6中 QLineEdit.EchoMode效果例子
  
'''

from PySide6.QtWidgets import (QApplication,
                               QLineEdit,
                               QWidget,
                               QFormLayout,)
import sys


# 定义一个名为lineEditDemo的类，继承自QWidget
class lineEditDemo(QWidget):
    # 初始化函数，参数为父类
    def __init__(self, parent=None):
        super(lineEditDemo, self).__init__(parent)
        # 设置窗口标题
        self.setWindowTitle("QLineEdit_EchoMode例子")
        
        # 创建一个QFormLayout布局
        flo = QFormLayout()
        # 创建一个QLineEdit对象
        pNormalLineEdit = QLineEdit()
        pNoEchoLineEdit = QLineEdit()
        pPasswordLineEdit = QLineEdit()
        pPasswordEchoOnEditLineEdit = QLineEdit()
        
        # 将QLineEdit对象添加到QFormLayout布局中
        flo.addRow("Normal", pNormalLineEdit)
        flo.addRow("NoEcho", pNoEchoLineEdit)
        flo.addRow("Password",pPasswordLineEdit)
        flo.addRow("PasswordEchoOnEdit",pPasswordEchoOnEditLineEdit)
        
        # 设置QLineEdit对象的占位符文本
        pNormalLineEdit.setPlaceholderText("Normal")
        pNoEchoLineEdit.setPlaceholderText("NoEcho")
        pPasswordLineEdit.setPlaceholderText("Password")
        pPasswordEchoOnEditLineEdit.setPlaceholderText("PasswordEchoOnEdit")
        
        
        # 设置QLineEdit对象的回显模式为Normal
        pNormalLineEdit.setEchoMode(QLineEdit.Normal)
        pNoEchoLineEdit.setEchoMode(QLineEdit.NoEcho)
        pPasswordLineEdit.setEchoMode(QLineEdit.Password)
        pPasswordEchoOnEditLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit)
        
        
        pNoEchoLineEdit.textEdited.connect(lambda: print(pNoEchoLineEdit.text()))
        
        # 将QFormLayout布局设置为当前类的布局
        self.setLayout(flo)
if __name__ == '__main__':
    app = QApplication(sys.argv)
    main_window = lineEditDemo()
    main_window.show()
    sys.exit(app.exec())